#ifndef JOYSTICK_DEVICE_H
#define JOYSTICK_DEVICE_H

#include <QObject>
#include <QSerialPort>
#include <QTimer>
#include <QVector>

class JoystickDevice : public QObject
{
    Q_OBJECT
  private:
    // QTimer* timer;
    QSerialPort *serialPort;
    QByteArray buffer;
    QVector<float> params;

  public:
    explicit JoystickDevice(QObject *parent = nullptr);
    ~JoystickDevice();
    bool InitDevice(const QString &device, int baudRate);
    void SetRemapParam(QVector<float> params);

  private:
    static float ExtractValue(const QByteArray &slice, float mid, float halfRange);
    bool CheckFrame(const QByteArray &frame);
    void DecodeFrame(const QByteArray &frame);
    void ReadData();

  signals:
    void OnInput(QVector<float> input);
};

#endif // JOYSTICK_DEVICE_H
